package com.dacool.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dacool.app.sale.R;

public abstract class BaseDialog extends Dialog {

	protected RelativeLayout contentView;
	protected TextView titleView;

	public BaseDialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		this.initView();
	}

	public BaseDialog(Context context, int theme) {
		// TODO Auto-generated constructor stub
		super(context, theme);
		this.initView();
	}

	public BaseDialog(Context context) {
		this(context, R.style.customDialog);
	}

	public BaseDialog setCustomTitle(CharSequence text) {
		titleView.setText(text);
		return this;
	}

	private void initView() {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.setContentView(R.layout.basedialog);
		contentView = (RelativeLayout) findViewById(R.id.contentView);
		titleView = (TextView) findViewById(R.id.titleView);
		View view = this.myView();
		if (view != null) {
			contentView.addView(view);
		} else if (myLayoutID() != 0) {
			view = LayoutInflater.from(getContext())
					.inflate(myLayoutID(), null);
			contentView.addView(view);
		}
	}

	@Override
	public void onAttachedToWindow() {
		// TODO Auto-generated method stub
		super.onAttachedToWindow();

	}

	protected abstract View myView();

	protected abstract int myLayoutID();

}
